#!/usr/bin/python
# -*- coding: UTF-8 -*- 
 
import os, re

folder_path = "dictionary/en_dict/"

with open(os.path.join(folder_path, "en_word_base_phoneme.dict"), "w") as fTgt:

	with open(os.path.join(folder_path, "cmudict-0.7b"), "r") as fSrc:
		for line in fSrc.readlines():
			line = line.strip('\n')  #去掉列表中每一个元素的换行符
			parts = line.split(" ")
			
			key = parts[0].lower()	#大写转小写

			match = re.findall(r"\(.*?\)", key)
			if len(match) > 0:
				continue

			first = True
			value = ""
			for p in parts:
				if p == "":
					continue
				elif first == True:
					first = False
					continue
				else:
					value += p + " "

			value = value[:-1]

			newline = key + "\t" + value

			fTgt.write(newline + "\n")

			print(newline)
